//
//  SeniorOperatorVC.swift
//  swiftDemo
//
//  Created by yaqiang bi on 2017/4/5.
//  Copyright © 2017年 毕小强. All rights reserved.
//

import UIKit

class SeniorOperatorVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        
        
        let vec1 = Vector2D(x: 2.0, y: 2.0)
        let vec2 = vec1++
        print(vec2.x)
        
        var original = Vector2D(x: 1.0, y: 2.0)
        var vectorToAdd = Vector2D(x: 3.0, y: 4.0)
        original += vectorToAdd
        
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
//运算符函数
struct Vector2D{
    var x = 0.0,y = 0.0
}
extension Vector2D{
    static func +(left:Vector2D,right:Vector2D)->Vector2D{
        return Vector2D(x: left.x+right.x, y: left.y+right.y)
    }
}
extension Vector2D{
    static postfix func ++(vector:Vector2D)->Vector2D{
        return Vector2D(x: vector.x + 1, y: vector.y + 1)
    }
}
extension Vector2D{
    static func += (left:inout Vector2D,right:Vector2D){
        left = left + right
    }
}
//自定义运算符
prefix operator +++
extension Vector2D{
    static prefix func +++ (vector:inout Vector2D)->Vector2D{
        vector += vector
        return vector
    }
}
